import React,{Component} from 'react';
import {Avatar,Row,Col} from 'antd';
import {connect} from 'react-redux';
import data from './data';
import UserList from './userList';
import {getUser} from '../../actions/user'
class User extends Component{
	constructor(props){
		super(props);
	}
	componentWillMount(){
		//console.log(this.props);
		this.props.dispatch(getUser(this.props.data, this.props.match.params.id))
	}
	render(){
		let {avatar_url,loginname,score,create_at,recent_topics,recent_replies} = this.props.data;
		let {loading} = this.props;
		return (
			<div className="wrap">
				<Avatar className="userAvatar" src={avatar_url}/>
				<Row className="userInfo">	
					<Col md={8}>用户名：<a>{loginname}</a></Col>
					<Col md={8}>积分：<a>{score}</a></Col>
					<Col md={8}>注册时间：<a>{create_at.split('T')[0]}</a></Col>
				</Row>
				<UserList loading={loading}
					title="最近创建的话题"
					data={recent_topics}
				/>
				<UserList loading={loading}
					title="最近回复的话题"
					data={recent_replies}
				/>
			</div>
		)
	}
}
export default connect(state=>state.user)(User);